package com.itany.template;

/**
 * Author:石小俊
 * Date: 2022/11/3 14:50
 */
public abstract class SortUtil<T> {

    public void sort(T[] arr){
        // 先制定一个顶层的业务逻辑,而将具体的细节留给子类去实现
        for(int i = 0; i < arr.length; i++){
            for(int j = i+1; j < arr.length; j++){
                int m = compareTo(arr[i],arr[j]);
                if(m > 0){
                    T temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
            }
        }
    }

    public abstract int compareTo(T t1,T t2);

}
class StringSortUtil extends SortUtil<String>{

    @Override
    public int compareTo(String s1, String s2) {
//        return s1.length()-s2.length();
        return s2.length()-s1.length();
    }
}